package cn.itcast.n8;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Phaser;

@Slf4j(topic = "c.TestPhaser")
public class TestPhaser {
    public static void main(String[] args) {
        final Phaser phaser = new Phaser(3);

        new Thread(() -> {
            log.debug("begin...");
            phaser.arriveAndAwaitAdvance();
//            phaser.arrive();
            log.debug("end...");
        },"t1").start();

        new Thread(() -> {
            log.debug("begin...");
            phaser.arriveAndAwaitAdvance();
//            phaser.arrive();
            log.debug("end...");
        },"t2").start();

        new Thread(() -> {
            log.debug("begin...");
            phaser.arriveAndAwaitAdvance();
            log.debug("end...");

        },"t3").start();


        phaser.awaitAdvance(phaser.getPhase());
        log.debug("{}",phaser.getPhase());

    }
}
